<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of manipulasi
 *
 * @author Obi
 */
class M_produk_det extends DataMapper {

    var $table = 'produk_det';
    var $key = 'id';

    function __construct() {
        parent::__construct();
    }

    //put your code here
    function insert($form) {
        $this->db->insert($this->table, $form);
    }

    function update($form, $id) {
        $this->db->where($this->key, $id);
        $this->db->update($this->table, $form);
    }

    function delete($id) {
        $this->db->where($this->key, $id);
        $this->db->delete($this->table);
    }

    function produk_det($id) {
        $sql = "select 
                    produk.*,
                    produk_det.*
                from 
                    produk, produk_det
                where 
                    produk_det.id_produk=produk.id and
                    produk_det.id='" . $id . "'";
        $query = $this->db->query($sql);
        return $query->row();
    }

    function update_produk($id = NULL, $bny = NULL) {
        $sql = "update produk_det " .
                "set " .
                "stok = stok-" . $bny . " " .
                "where id='" . $id . "'";
        $query = $this->db->query($sql);
    }

    function roll_update_produk($id = NULL, $bny = NULL) {
        $sql = "update produk_det " .
                "set " .
                "stok = stok+" . $bny . " " .
                "where id='" . $id . "'";
        $query = $this->db->query($sql);
    }

    function report_produk_det() {
        $sql = "select 
                    produk.*,
                    produk_det.*
                from 
                    produk, produk_det
                where 
                    produk_det.id_produk=produk.id ";
        $query = $this->db->query($sql);
        return $query->result();
    }

}

?>
